﻿using Heroius.Activator;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Heroius.Indexer
{
    internal static class ActivatorHelper
    {
        internal static void Initialize()
        {
            licensed = false;
            licpath = Application.StartupPath + @"\lic";
            licmgr = new LicenseManager();
        }

        internal static string licpath { get; private set; }

        internal static ProductLicense lic
        {
            get { return _lic; }
            set
            {
                _lic = value;
                licmgr.SaveLicense(licpath, lic);
                Action cache = licChanged;
                if (cache != null)
                {
                    cache();
                }
            }
        }
        static ProductLicense _lic = null;

        internal static LicenseManager licmgr { get; private set; }

        internal static bool licensed { get; private set; }

        internal static void TryActivate()
        {
            if (File.Exists(licpath))
            {
                ActivatorHelper.lic = licmgr.LoadLicense(licpath);
                licensed = true;
            }
            else
            {
                DiaActivate dia = new DiaActivate();
                if (dia.ShowDialog() == DialogResult.OK)
                {
                    licensed = true;
                }
            }
        }

        internal static event Action licChanged;
    }
}
